package com.market.pay.details;

import com.market.entity.base.Fruit;
import com.market.entity.dto.OrderDto;
import com.market.pay.base.PricingStrategy;
import com.market.util.CommonConstants;

import java.math.BigDecimal;

public class StrawberryDiscountStrategy implements PricingStrategy {
    private final PricingStrategy baseStrategy;


    public StrawberryDiscountStrategy(PricingStrategy baseStrategy) {
        this.baseStrategy = baseStrategy;
    }

    @Override
    public BigDecimal calculateTotal(OrderDto orderDto) {
        BigDecimal baseTotal = baseStrategy.calculateTotal(orderDto);
        BigDecimal strawberryDiscount = BigDecimal.ZERO;

        if (orderDto.getItems().containsKey(Fruit.STRAWBERRY)) {
            BigDecimal strawberryWeight = orderDto.getItems().get(Fruit.STRAWBERRY);
            BigDecimal originalPrice = Fruit.STRAWBERRY.getFruitPrice().multiply(strawberryWeight);
            BigDecimal discountedPrice = originalPrice.multiply(CommonConstants.STRAWBERRY_DISCOUNT_RATE);
            strawberryDiscount = originalPrice.subtract(discountedPrice);
        }

        return baseTotal.subtract(strawberryDiscount);
    }
}
